package sebastiankerckhof.scene;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import sebastiankerckhof.math.Color3f;
import sebastiankerckhof.render.raytrace.Ray;
import sebastiankerckhof.render.raytrace.Hit.Hit;
import sebastiankerckhof.scene.geometry.BVHNode;
import sebastiankerckhof.scene.geometry.Surface;
import sebastiankerckhof.scene.lighting.Light;
import sebastiankerckhof.scene.texture.BasicTexture;
import sebastiankerckhof.scene.texture.TexCoord2f;
import sebastiankerckhof.scene.texture.Texture;

public class Scene{

	public BVHNode surfaces;
	public List<Light> lights = new ArrayList<Light>();
	public Camera camera;
	public Color3f backgroundColor;
	public Texture bg ;
	//public List<Surface> surfaces;
	
	public Scene(){
		try {
	    this.bg = new BasicTexture("stars.jpg");
    } catch (IOException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
    }
	}
	
	public Color3f getBackgroundColor(Ray r){
		return this.backgroundColor;
		/*if(bg != null){
			float u = (r.direction.x + r.direction.y) / (2*r.direction.x);
			float v = (r.direction.x + r.direction.z) / (2*r.direction.x);
			return bg.getColor(new TexCoord2f(u,v));
		}else{
			return this.backgroundColor;
		}*/
	}
	
	public void setBackgroundColor(Color3f color){
		this.backgroundColor = color;
	}
	
	public void setSurfaces(List<Surface> surfaces){
		//this.surfaces = surfaces;
		this.surfaces = new BVHNode(surfaces,0);
	}
	
	
	/*public List<Triangle> getTriangles(){
		List<Triangle> triangles = new LinkedList<Triangle>();
		for(Surface h : surfaces){
			Mesh m = (Mesh) h;
			triangles.addAll(Arrays.asList(m.triangles));
		}
		return triangles;
	}*/


	public void transformToStep(float step){
		this.surfaces.transformToStep(step);
	}
	
	public void transformFromStep(float step){
		this.surfaces.transformFromStep(step);
	}
	
  public boolean hit(Ray r, float t0, Hit h) {
  		return surfaces.hit(r, t0, h);
  }


}
